********************************************************************************
*                                                                              *
*           WHY DO PEOPLE USE INFORMAL JUSTICE? REPLICATION (JEPS)             *
*                                                                              *
********************************************************************************

    


* define data and results paths (fill in with your own URL)
	global PathData = "/Users/krzysztofkrakowski/Dropbox/Kosovo project/2_Orders/1_Data/"
	global PathTab = "/Users/krzysztofkrakowski/Dropbox/Kosovo project/2_Orders/4_Writing/z_tables/to_edit/"
	global PathFig = "/Users/krzysztofkrakowski/Dropbox/Kosovo project/2_Orders/4_Writing/z_figures/"
	

* upload the main data file (with original survey)
	use "${PathData}kosovo_survey.dta", clear


* merge data summing informal dispute settlement cases that appeared in the news
merge m:1 KOMUNA using "${PathData}media.dta",  force





*** prepare outcome in three steps


* first use lower cases in vignette strings
gen orders_1 = lower(VINJETA1RANDOM)
gen orders_2 = lower(VINJETA2RANDOM)


* identify vignette type by keywords
	* debt *
gen orders_1_civil_debt = strpos(orders_1,"borg") 
replace orders_1_civil_debt = orders_1_civil_debt>0
gen orders_2_civil_debt = strpos(orders_2,"borg") 
replace orders_2_civil_debt = orders_2_civil_debt>0
	* inheritance *
gen orders_1_civil_inheritance =  strpos(orders_1,"toke")
replace orders_1_civil_inheritance = orders_1_civil_inheritance>0
gen orders_2_civil_inheritance = strpos(orders_2,"toke")
replace orders_2_civil_inheritance = orders_2_civil_inheritance>0
	* domestic violence *
gen orders_1_criminal_domestic = strpos(orders_1,"rrahur") 
replace orders_1_criminal_domestic = orders_1_criminal_domestic>0 
gen orders_2_criminal_domestic = strpos(orders_2,"rrahur")
replace orders_2_criminal_domestic = orders_2_criminal_domestic>0 
	* murder *
gen orders_1_criminal_murder = strpos(orders_1,"rinj")
replace orders_1_criminal_murder = orders_1_criminal_murder>0  
gen orders_2_criminal_murder = strpos(orders_2,"rinj")
replace orders_2_criminal_murder = orders_2_criminal_murder>0  



* code outcome variables 
    * debt *
gen legal_civil_debt=. 
replace legal_civil_debt=PERGJIGJJETAI1 if orders_1_civil_debt==1
replace legal_civil_debt=PERGJIGJJETAI2 if orders_2_civil_debt==1
    * inheritance *
gen legal_civil_inheritance=. 
replace legal_civil_inheritance=PERGJIGJJETAI1 if orders_1_civil_inheritance==1
replace legal_civil_inheritance=PERGJIGJJETAI2 if orders_2_civil_inheritance==1
    * domestic violence *
gen legal_criminal_domestic=. 
replace legal_criminal_domestic=PERGJIGJJETAI1 if orders_1_criminal_domestic==1
replace legal_criminal_domestic=PERGJIGJJETAI2 if orders_2_criminal_domestic==1
    * murder *
gen legal_criminal_murder=. 
replace legal_criminal_murder=PERGJIGJJETAI1 if orders_1_criminal_murder==1
replace legal_criminal_murder=PERGJIGJJETAI2 if orders_2_criminal_murder==1




*** prepare treatment variables in two steps
 

* decode treatments by keywords (in vigentte 1)
    * resorucelessnesss (vignette 1)
gen orders_1_t1 = strpos(orders_1,"varf") + strpos(orders_1,"dob")
replace orders_1_t1 = orders_1_t1>0
    * inefficiency (vignette 1)
gen orders_1_t2 = strpos(orders_1,"ngadal")
replace orders_1_t2 = orders_1_t2>0
    * conventions (vignette 1)
gen orders_1_t3 = strpos(orders_1,"nuk p")
replace orders_1_t3 = orders_1_t3>0

* decode treatments by keywords (in vigentte 2)
    * resorucelessnesss (vignette 2)
gen orders_2_t1 = strpos(orders_2,"varf") + strpos(orders_2,"dob")
replace orders_2_t1 = orders_2_t1>0
    * inefficiency (vignette 2)
gen orders_2_t2 = strpos(orders_2,"ngadal")
replace orders_2_t2 = orders_2_t2>0
    * conventions (vignette 2)
gen orders_2_t3 = strpos(orders_2,"nuk p")
replace orders_2_t3 = orders_2_t3>0



* code treatment variables 
    * resourcelessness, debt *
gen legal_civil_debt_t1=. 
replace legal_civil_debt_t1=orders_1_t1 if orders_1_civil_debt==1
replace legal_civil_debt_t1=orders_2_t1 if orders_2_civil_debt==1
    * resourcelessness, inheritance *
gen legal_civil_inheritance_t1=. 
replace legal_civil_inheritance_t1=orders_1_t1 if orders_1_civil_inheritance==1
replace legal_civil_inheritance_t1=orders_2_t1 if orders_2_civil_inheritance==1
    * resourcelessness, domestic violence *
gen legal_criminal_domestic_t1=. 
replace legal_criminal_domestic_t1=orders_1_t1 if orders_1_criminal_domestic==1
replace legal_criminal_domestic_t1=orders_2_t1 if orders_2_criminal_domestic==1
    * resourcelessness, murder *
gen legal_criminal_murder_t1=. 
replace legal_criminal_murder_t1=orders_1_t1 if orders_1_criminal_murder==1
replace legal_criminal_murder_t1=orders_2_t1 if orders_2_criminal_murder==1

    * inefficiency, debt *
gen legal_civil_debt_t2=. 
replace legal_civil_debt_t2=orders_1_t2 if orders_1_civil_debt==1
replace legal_civil_debt_t2=orders_2_t2 if orders_2_civil_debt==1
    * inefficiency, inheritance *
gen legal_civil_inheritance_t2=. 
replace legal_civil_inheritance_t2=orders_1_t2 if orders_1_civil_inheritance==1
replace legal_civil_inheritance_t2=orders_2_t2 if orders_2_civil_inheritance==1
    * inefficiency, domestic violence *
gen legal_criminal_domestic_t2=. 
replace legal_criminal_domestic_t2=orders_1_t2 if orders_1_criminal_domestic==1
replace legal_criminal_domestic_t2=orders_2_t2 if orders_2_criminal_domestic==1
    * inefficiency, murder *
gen legal_criminal_murder_t2=. 
replace legal_criminal_murder_t2=orders_1_t2 if orders_1_criminal_murder==1
replace legal_criminal_murder_t2=orders_2_t2 if orders_2_criminal_murder==1

    * conventions, debt *
gen legal_civil_debt_t3=. 
replace legal_civil_debt_t3=orders_1_t3 if orders_1_civil_debt==1
replace legal_civil_debt_t3=orders_2_t3 if orders_2_civil_debt==1
    * conventions, inheritance *
gen legal_civil_inheritance_t3=. 
replace legal_civil_inheritance_t3=orders_1_t3 if orders_1_civil_inheritance==1
replace legal_civil_inheritance_t3=orders_2_t3 if orders_2_civil_inheritance==1
    * conventions, domestic violence *
gen legal_criminal_domestic_t3=. 
replace legal_criminal_domestic_t3=orders_1_t3 if orders_1_criminal_domestic==1
replace legal_criminal_domestic_t3=orders_2_t3 if orders_2_criminal_domestic==1
    * conventions, murder *
gen legal_criminal_murder_t3=. 
replace legal_criminal_murder_t3=orders_1_t3 if orders_1_criminal_murder==1
replace legal_criminal_murder_t3=orders_2_t3 if orders_2_criminal_murder==1




*** recode outcomes in binary variables (state vs nonstate justice)

    * debt *
gen legal_civil_debt_bin=1 if legal_civil_debt>1
replace legal_civil_debt_bin=0 if legal_civil_debt==1
    * inheritance *
gen legal_civil_inheritance_bin=1 if legal_civil_inheritance>1
replace legal_civil_inheritance_bin=0 if legal_civil_inheritance==1
    * domestic violence *
gen legal_criminal_domestic_bin=1 if legal_criminal_domestic>1
replace legal_criminal_domestic_bin=0 if legal_criminal_domestic==1
    * murder *
gen legal_criminal_murder_bin=1 if legal_criminal_murder>1
replace legal_criminal_murder_bin=0 if legal_criminal_murder==1




*** label variables

label variable	legal_civil_debt "Justice type (debt)"
label variable	legal_civil_inheritance "Justice type (inheritance)"
label variable	legal_criminal_domestic "Justice type (domestic violence)"
label variable	legal_criminal_murder "Justice type (murder)"

label variable	legal_civil_debt_bin "State justice (debt)"
label variable	legal_civil_inheritance_bin "State justice (inheritance)"
label variable	legal_criminal_domestic_bin "State justice (domestic violence)"
label variable	legal_criminal_murder_bin "State justice (murder)"

label define justice_types 1 "State justice" 2 "Religious justice" 3 "Community justice"
label values	legal_civil_debt justice_types
label values	legal_civil_inheritance justice_types
label values	legal_criminal_domestic justice_types
label values	legal_criminal_murder justice_types

label variable	legal_civil_debt_t1 "Resourcelessness"
label variable	legal_civil_debt_t2 "Inefficiency"
label variable	legal_civil_debt_t3 "Conventions"
label variable	legal_civil_inheritance_t1 "Resourcelessness"
label variable	legal_civil_inheritance_t2 "Inefficiency"
label variable	legal_civil_inheritance_t3 "Conventions"
label variable	legal_criminal_domestic_t1 "Resourcelessness"
label variable	legal_criminal_domestic_t2 "Inefficiency"
label variable	legal_criminal_domestic_t3 "Conventions"
label variable	legal_criminal_murder_t1 "Resourcelessness"
label variable	legal_criminal_murder_t2 "Inefficiency"
label variable	legal_criminal_murder_t3 "Conventions"


* standardize variables and label
zval legal_civil_debt_bin legal_civil_inheritance_bin legal_criminal_domestic_bin legal_criminal_murder_bin    legal_civil_debt_t1 legal_civil_debt_t2 legal_civil_debt_t3 legal_civil_inheritance_t1  legal_civil_inheritance_t2  legal_civil_inheritance_t3     legal_criminal_domestic_t1  legal_criminal_domestic_t2  legal_criminal_domestic_t3  legal_criminal_murder_t1    legal_criminal_murder_t2    legal_criminal_murder_t3
label variable  z_legal_civil_debt_t1 "Resourcelessness (z)"
label variable  z_legal_civil_debt_t2 "Inefficiency (z)"
label variable  z_legal_civil_debt_t3 "Conventions (z)"
label variable  z_legal_civil_inheritance_t1 "Resourcelessness (z)"
label variable  z_legal_civil_inheritance_t2 "Inefficiency (z)"
label variable  z_legal_civil_inheritance_t3 "Conventions (z)"
label variable  z_legal_criminal_domestic_t1 "Resourcelessness (z)"
label variable  z_legal_criminal_domestic_t2 "Inefficiency (z)"
label variable  z_legal_criminal_domestic_t3 "Conventions (z)"
label variable  z_legal_criminal_murder_t1 "Resourcelessness (z)"
label variable  z_legal_criminal_murder_t2 "Inefficiency (z)"
label variable  z_legal_criminal_murder_t3 "Conventions (z)"





*** code respondents' own legal preferences 
    * debt *
gen legal_debt_own=. 
replace legal_debt_own=PERGJIJETAI1 if orders_1_civil_debt==1
replace legal_debt_own=PERGJIJETAI21 if orders_2_civil_debt==1
    * inheritance *
gen legal_inheritance_own=. 
replace legal_inheritance_own=PERGJIJETAI1 if orders_1_civil_inheritance==1
replace legal_inheritance_own=PERGJIJETAI21 if orders_2_civil_inheritance==1
    * domestic violence *
gen legal_domestic_own=. 
replace legal_domestic_own=PERGJIJETAI1 if orders_1_criminal_domestic==1
replace legal_domestic_own=PERGJIJETAI21 if orders_2_criminal_domestic==1
    * murder *
gen legal_murder_own=. 
replace legal_murder_own=PERGJIJETAI1 if orders_1_criminal_murder==1
replace legal_murder_own=PERGJIJETAI21 if orders_2_criminal_murder==1

* dichotomize respondents' own legal preferences
recode	legal_debt_own (1 = 0) (2 3 = 1), gen(legal_debt_own_bin)
recode	legal_inheritance_own (1 = 0) (2 3 = 1), gen(legal_inheritance_own_bin)
recode	legal_domestic_own (1 = 0) (2 3 = 1), gen(legal_domestic_own_bin)
recode	legal_murder_own (1 = 0) (2 3 = 1), gen(legal_murder_own_bin)




*** code respondent-level indicators of resourcelessness, beliefs about state justice inefficiency and average legal preferences in their municipalities
recode Q34 (1 2 = 0) (3 = 1), gen(treat1)
recode Q8 (1/3 = 0) (4/5 = 1), gen(treat2)
bysort KOMUNA: egen treat3_debt=mean(legal_debt_own_bin)
bysort KOMUNA: egen treat3_inheritance=mean(legal_inheritance_own_bin)
bysort KOMUNA: egen treat3_domestic=mean(legal_domestic_own_bin)
bysort KOMUNA: egen treat3_murder=mean(legal_murder_own_bin)
    * label additional variables
label variable treat1 "Resourcelessness"
label variable treat2 "Inefficiency"
label variable treat3_debt "Conventions"
label variable treat3_inheritance "Conventions"
label variable treat3_domestic "Conventions"
label variable treat3_murder "Conventions"
* standardize additional variables and label
zval legal_debt_own_bin legal_inheritance_own_bin legal_domestic_own_bin legal_murder_own_bin  treat1	treat2	treat3_debt	treat3_inheritance	treat3_domestic	treat3_murder
label variable z_treat1 "Resourcelessness"
label variable z_treat2 "Inefficiency"
label variable z_treat3_debt "Conventions"
label variable z_treat3_inheritance "Conventions"
label variable z_treat3_domestic "Conventions"
label variable z_treat3_murder "Conventions"




* recode informal dispute settlement cases (from the media data) at the municipality level
egen informal_cases = rowtotal(debtcases murdercases property domesticviolencecases)
egen informal_cases_criminal = rowtotal( murdercases  domesticviolencecases)
egen informal_norms = rowmean(treat3_inheritance treat3_murder treat3_debt treat3_domestic)
    * per 1,000 inhabitants
gen informal_cases_cap2 = informal_cases/(population/1000)




* construct informal dispute settlement cases by municipal crime data
gen informal_cases_cap = informal_cases/(dv_2020+theft_2020+murder_2020)
gen debt_cases_cap = debtcases/(dv_2020+theft_2020+murder_2020)
gen murder_cases_cap = murdercases/(dv_2020+theft_2020+murder_2020)
gen property_cases_cap = property/(dv_2020+theft_2020+murder_2020)
gen domestic_cases_cap = domesticviolencecases/(dv_2020+theft_2020+murder_2020)
egen crimes_tot = rowtotal(dv_2020 theft_2020 murder_2020), missing




* aggregate survey data at the municipality
bys KOMUNA: gen count = _n
bysort KOMUNA: egen poor_mean=mean(Q34)
bysort KOMUNA: egen mistrust_mean=mean(Q8)




* take logs of key variables
gen lnpop = ln(population)
gen lninformal = ln(informal_cases+1)
gen ln_norms = ln(informal_norms+0.1)
gen ln_cases = ln(informal_cases_cap+0.1)
gen ln_cases2 = ln(informal_cases_cap2+0.1)
gen ln_mistrust = ln(mistrust_mean+0.1)
gen ln_poor = ln(poor_mean+0.1)
    * and label
label variable ln_poor "Resourcelessness (mun)"
label variable ln_mistrust "Inefficiency (mun)"
label variable ln_norms "Conventions (mun)"
    * and standardize
zval ln_poor ln_mistrust ln_norms poor_mean mistrust_mean informal_norms






*** produce tables and figures



* Figure A4
twoway (lfit ln_cases2 ln_norms if count==1) (scatter ln_cases2 ln_norms if count==1) (lfit ln_cases2 ln_mistrust if count==1) (scatter ln_cases2 ln_mistrust if count==1) 
    * labels need to be manually edited before saving the figure as FigureA4.png


* Figure A5 
twoway (lfit ln_cases ln_norms if count==1) (scatter ln_cases ln_norms if count==1) (lfit ln_cases ln_mistrust if count==1) (scatter ln_cases ln_mistrust if count==1) 
   * labels need to be manually edited before saving the figure as FigureA5.png



* Table A10
eststo clear
eststo Informal_Settlements_1: nbreg informal_cases z_ln_poor z_ln_mistrust z_ln_norms if count==1, exp(crimes_tot)  
eststo Informal_Settlements_2: nbreg informal_cases z_ln_poor z_ln_mistrust z_ln_norms lnpop if count==1, exp(crimes_tot)  
eststo Informal_Settlements_3: nbreg informal_cases_criminal z_ln_poor z_ln_mistrust z_ln_norms lnpop if count==1, exp(crimes_tot)  
esttab Informal_Settlements_1 Informal_Settlements_2 Informal_Settlements_3 using "${PathTab}TableA10.tex", b(3) se(3) star(* 0.1 ** 0.05 *** 0.01) drop(_cons) label nodepvar mtitles title("Determinants of Informal Dispute Settlement: Municipal-Level Analysis") replace nonotes postfoot(" ")




